import request from '@/utils/request'

// ==================== 文件管理 ====================

// 获取文件列表
export function getFileList(params) {
  return request({
    url: '/api/zenithMind/disk/files',
    method: 'get',
    params
  })
}

// 获取文件夹内容
export function getFolderContent(folderId, params) {
  return request({
    url: `/api/zenithMind/disk/folders/${folderId}/content`,
    method: 'get',
    params
  })
}

// 上传文件
export function uploadFile(formData, onProgress) {
  return request({
    url: '/api/zenithMind/disk/files/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    onUploadProgress: onProgress
  })
}

// 批量上传文件
export function batchUploadFiles(formData, onProgress) {
  return request({
    url: '/api/zenithMind/disk/files/batch-upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    onUploadProgress: onProgress
  })
}

// 下载文件
export function downloadFile(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/download`,
    method: 'get',
    responseType: 'blob'
  })
}

// 获取文件下载链接
export function getDownloadUrl(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/download-url`,
    method: 'get'
  })
}

// 预览文件
export function previewFile(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/preview`,
    method: 'get'
  })
}

// 获取文件信息
export function getFileInfo(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}`,
    method: 'get'
  })
}

// 重命名文件
export function renameFile(fileId, newName) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/rename`,
    method: 'put',
    data: { name: newName }
  })
}

// 移动文件
export function moveFile(fileId, targetFolderId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/move`,
    method: 'put',
    data: { targetFolderId }
  })
}

// 复制文件
export function copyFile(fileId, targetFolderId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/copy`,
    method: 'post',
    data: { targetFolderId }
  })
}

// 删除文件
export function deleteFile(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}`,
    method: 'delete'
  })
}

// 批量删除文件
export function batchDeleteFiles(fileIds) {
  return request({
    url: '/api/zenithMind/disk/files/batch-delete',
    method: 'delete',
    data: { fileIds }
  })
}

// ==================== 文件夹管理 ====================

// 创建文件夹
export function createFolder(data) {
  return request({
    url: '/api/zenithMind/disk/folders',
    method: 'post',
    data
  })
}

// 获取文件夹信息
export function getFolderInfo(folderId) {
  return request({
    url: `/api/zenithMind/disk/folders/${folderId}`,
    method: 'get'
  })
}

// 重命名文件夹
export function renameFolder(folderId, newName) {
  return request({
    url: `/api/zenithMind/disk/folders/${folderId}/rename`,
    method: 'put',
    data: { name: newName }
  })
}

// 移动文件夹
export function moveFolder(folderId, targetFolderId) {
  return request({
    url: `/api/zenithMind/disk/folders/${folderId}/move`,
    method: 'put',
    data: { targetFolderId }
  })
}

// 删除文件夹
export function deleteFolder(folderId) {
  return request({
    url: `/api/zenithMind/disk/folders/${folderId}`,
    method: 'delete'
  })
}

// 获取文件夹树
export function getFolderTree() {
  return request({
    url: '/api/zenithMind/disk/folders/tree',
    method: 'get'
  })
}

// ==================== 文件分享 ====================

// 创建分享链接
export function createShare(data) {
  return request({
    url: '/api/zenithMind/disk/shares',
    method: 'post',
    data
  })
}

// 获取我的分享
export function getMyShares(params) {
  return request({
    url: '/api/zenithMind/disk/shares/my',
    method: 'get',
    params
  })
}

// 获取分享信息
export function getShareInfo(shareCode) {
  return request({
    url: `/api/zenithMind/disk/shares/${shareCode}`,
    method: 'get'
  })
}

// 访问分享文件
export function accessShare(shareCode, password) {
  return request({
    url: `/api/zenithMind/disk/shares/${shareCode}/access`,
    method: 'post',
    data: { password }
  })
}

// 取消分享
export function cancelShare(shareId) {
  return request({
    url: `/api/zenithMind/disk/shares/${shareId}`,
    method: 'delete'
  })
}

// 保存分享文件到我的网盘
export function saveSharedFile(shareCode, fileId, targetFolderId) {
  return request({
    url: `/api/zenithMind/disk/shares/${shareCode}/save`,
    method: 'post',
    data: { fileId, targetFolderId }
  })
}

// ==================== 回收站管理 ====================

// 获取回收站文件
export function getRecycleBinFiles(params) {
  return request({
    url: '/api/zenithMind/disk/recycle-bin',
    method: 'get',
    params
  })
}

// 恢复文件
export function restoreFile(fileId) {
  return request({
    url: `/api/zenithMind/disk/recycle-bin/${fileId}/restore`,
    method: 'post'
  })
}

// 彻底删除文件
export function permanentDeleteFile(fileId) {
  return request({
    url: `/api/zenithMind/disk/recycle-bin/${fileId}`,
    method: 'delete'
  })
}

// 清空回收站
export function clearRecycleBin() {
  return request({
    url: '/api/zenithMind/disk/recycle-bin/clear',
    method: 'delete'
  })
}

// ==================== 存储空间管理 ====================

// 获取存储空间信息
export function getStorageInfo() {
  return request({
    url: '/api/zenithMind/disk/storage/info',
    method: 'get'
  })
}

// 获取存储空间使用统计
export function getStorageStats() {
  return request({
    url: '/api/zenithMind/disk/storage/stats',
    method: 'get'
  })
}

// ==================== 文件搜索 ====================

// 搜索文件
export function searchFiles(keyword, params) {
  return request({
    url: '/api/zenithMind/disk/files/search',
    method: 'get',
    params: { keyword, ...params }
  })
}

// 高级搜索
export function advancedSearch(searchParams) {
  return request({
    url: '/api/zenithMind/disk/files/advanced-search',
    method: 'post',
    data: searchParams
  })
}

// ==================== 文件标签 ====================

// 获取文件标签
export function getFileTags(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/tags`,
    method: 'get'
  })
}

// 添加文件标签
export function addFileTag(fileId, tag) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/tags`,
    method: 'post',
    data: { tag }
  })
}

// 删除文件标签
export function removeFileTag(fileId, tagId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/tags/${tagId}`,
    method: 'delete'
  })
}

// 获取所有标签
export function getAllTags() {
  return request({
    url: '/api/zenithMind/disk/tags',
    method: 'get'
  })
}

// ==================== 文件版本管理 ====================

// 获取文件版本历史
export function getFileVersions(fileId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/versions`,
    method: 'get'
  })
}

// 恢复文件版本
export function restoreFileVersion(fileId, versionId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/versions/${versionId}/restore`,
    method: 'post'
  })
}

// 删除文件版本
export function deleteFileVersion(fileId, versionId) {
  return request({
    url: `/api/zenithMind/disk/files/${fileId}/versions/${versionId}`,
    method: 'delete'
  })
}
